package com.rockcent.wechat;

import com.rockcent.common.common.RWebMvcConfigurerAdapter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;

import java.util.Arrays;

/**
 * Created by oyhk on 15-2-15.
 *
 */
@Configuration
@EnableWebMvc
public class WebMvcConfig extends RWebMvcConfigurerAdapter {

    @Autowired
    private AuthInterceptor authInterceptor;
    @Autowired
    private DomainInterceptor domainInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        super.addInterceptors(registry);
        registry.addInterceptor(domainInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns(
                        "/monitor/telnet/info",
                        "/api/v2/wechat/config",
                        "/api/v2/mall/wechat_appid",
                        "/api/v2/payment_notify/**"
                );
        registry.addInterceptor(authInterceptor)
                .addPathPatterns(
                        "/api/v2/sms/**",
                        "/api/v2/red_packet/**",
                        "/api/v2/payment/**",
                        "/api/v2/product/**",
                        "/api/v2/channel/**",
                        "/api/v2/merchant/**",
                        "/api/v2/customer/**",
                        "/api/v2/order/**",
                        "/api/v2/shopping_cart/**",
                        "/api/v2/mall/**")
                .excludePathPatterns(
                        "/api/v2/mall/wechat_appid",
                        "/integration/coupons",
                        "/integration/coupon/**");
    }
}
